//
//  HeadVC.m
//  代理端
//
//  Created by sliver on 15/12/11.
//  Copyright (c) 2015年 sliver. All rights reserved.
//

#import "HeadVC.h"
#import "AgentVC.h"
#import "BalanceVC.h"
#import "StockVC.h"
#import "ApplyVC.h"
#import "AboutOurVC.h"
#import "ShoppingMainVC.h"
#import "OrderMainVC.h"
#import "UIImageView+WebCache.h"
@interface HeadVC ()
{
    UIImageView *imgview;
    UILabel *conpnayLab; //公司名
    UILabel *rankLab; //级别
    UIView *mainView;
}
@end

@implementation HeadVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadView1];
    [self loadNav];
    
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ceshi:) name:@"ceshi" object:nil];

}
-(void)ceshi:(NSNotification *)info
{
//    NSLog(@"info = ====%@",info);
    
    NSDictionary *dic = [info userInfo];
    NSString *str = [dic objectForKey:@"vc"];
    
    UIViewController *vc = [[NSClassFromString(str) alloc] init];
    [self presentViewController:vc animated:YES completion:nil];
}
-(void)loadView1{
    self.view.backgroundColor =[UIColor whiteColor];
    //照片
    imgview = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenW / 2 -50*KScr, 100*KScr, 100*KScr, 100*KScr)];
   NSString *string =  [NSString stringWithFormat:@"%@%@",BASE_URL,USER_IMG];
    NSURL *imgurl = [NSURL URLWithString:string];
    imgview.layer.masksToBounds = YES;
    imgview.layer.cornerRadius = 5*KScr;
    imgview.backgroundColor = [UIColor whiteColor];
    [imgview setImageWithURL:imgurl placeholderImage:[UIImage imageNamed:@"代理商信息头像_150.png"]];
    imgview.userInteractionEnabled =YES;
    //单击手势
    UITapGestureRecognizer *sigleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(signalTapAction)];
    //设置点击手指的根数
    sigleTap.numberOfTouchesRequired = 1;
    //点击屏幕次数
    sigleTap.numberOfTapsRequired = 1;
    [imgview addGestureRecognizer:sigleTap];

    [self.view addSubview:imgview];
    ;
    //公司名
    conpnayLab = [[UILabel alloc]initWithFrame:CGRectMake(50*KScr, 210*KScr, ScreenW - 100*KScr, 20*KScr)];
    conpnayLab.text = CPOMANY_NAME;
    conpnayLab.textColor = [UIColor blackColor];
    conpnayLab.textAlignment = NSTextAlignmentCenter;
    conpnayLab.font = [UIFont boldSystemFontOfSize:19*KScr];
    [self.view addSubview:conpnayLab];
    //级别
    rankLab = [[UILabel alloc]initWithFrame:CGRectMake(50*KScr, 240*KScr, ScreenW - 100*KScr, 20*KScr)];
    switch ([USER_LEVEL integerValue]) {
        case 1:
            rankLab.text =@"省级代理";
            break;
        case 2:
            rankLab.text =@"市级代理";
            break;
        case 3:
            rankLab.text =@"县级代理";
            break;
        case 4:
            rankLab.text =@"采集代理";
            break;
            
        default:
            break;
    }
    rankLab.font = [UIFont systemFontOfSize:15*KScr];
    rankLab.textAlignment = NSTextAlignmentCenter;
    rankLab.textColor = [UIColor grayColor];
    [self.view addSubview:rankLab];
    
    //申请返利
    UIButton *fanliBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, ScreenH-ScreenW/3, ScreenW/2, ScreenW/3)];
    [fanliBtn setBackgroundImage:[UIImage imageNamed:@"申请返利"] forState:UIControlStateNormal];
    [fanliBtn addTarget:self action:@selector(fanli) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:fanliBtn];
    //关于我们
    UIButton *womenBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenW/2, ScreenH-ScreenW/3, ScreenW/2,  ScreenW/3)];
    [womenBtn setBackgroundImage:[UIImage imageNamed:@"关于我们.png"] forState:UIControlStateNormal];
    [womenBtn addTarget:self action:@selector(women) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:womenBtn];
     //余额
    UIButton *yueBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, ScreenH-ScreenW*2/3, ScreenW/2,  ScreenW/3)];
    [yueBtn setBackgroundImage:[UIImage imageNamed:@"矩形-3.png"] forState:UIControlStateNormal];
    [yueBtn addTarget:self action:@selector(yue) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:yueBtn];
     //库存
    UIButton *kucunBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenW/2, ScreenH-ScreenW*2/3, ScreenW/2,  ScreenW/3)];
    [kucunBtn setBackgroundImage:[UIImage imageNamed:@"库存"] forState:UIControlStateNormal];
    [kucunBtn addTarget:self action:@selector(kucun) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:kucunBtn];
    //商城
    UIButton *shanhchengBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, ScreenH-ScreenW, ScreenW/2,  ScreenW/3)];
    [shanhchengBtn setBackgroundImage:[UIImage imageNamed:@"商城"] forState:UIControlStateNormal];
    [shanhchengBtn addTarget:self action:@selector(shangcheng) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shanhchengBtn];
    //订单
    UIButton *dingdanBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenW/2, ScreenH-ScreenW, ScreenW/2,  ScreenW/3)];
    [dingdanBtn setBackgroundImage:[UIImage imageNamed:@"订单.png"] forState:UIControlStateNormal];
    [dingdanBtn addTarget:self action:@selector(dingdan) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dingdanBtn];


}
-(void)loadNav{
    UIView *redview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    redview.backgroundColor = DRINK_RED_COLOR;
    [self.view addSubview:redview];
    
    UILabel *redLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenW, 44)];
    redLab.backgroundColor = DRINK_RED_COLOR;
    redLab.text = @"九道坊代理商";
    redLab.textColor = [UIColor whiteColor];
    redLab.textAlignment =  NSTextAlignmentCenter;
    redLab.font = [UIFont boldSystemFontOfSize:17];
    [self.view addSubview:redLab];
//    [mainView addSubview:redLab];
    
//    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 20,44, 40)];
//    backBtn.adjustsImageWhenHighlighted = NO;
//    [backBtn setImage:[UIImage imageNamed:@"菜单"] forState:UIControlStateNormal];
//    [backBtn addTarget:self action:@selector(clickBack:) forControlEvents:UIControlEventTouchUpInside];
//    [mainView addSubview:backBtn];
}
#pragma mark - 返利
-(void)fanli{
    ApplyVC *applyvc = [[ApplyVC alloc]init];
    applyvc.modalPresentationStyle = UIModalPresentationFullScreen;
    applyvc.fromto = fromtypetoOther;
    [self presentViewController:applyvc animated:YES completion:nil];
}
#pragma mark - 关于我们
-(void)women{
    AboutOurVC *applyvc = [[AboutOurVC alloc]init];
    applyvc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:applyvc animated:YES completion:nil];
}
#pragma mark - 余额
-(void)yue{
    BalanceVC *applyvc = [[BalanceVC alloc]init];
    applyvc.modalPresentationStyle = UIModalPresentationFullScreen;
    applyvc.fromto = fromTypeOther;
    [self presentViewController:applyvc animated:YES completion:nil];

}
#pragma mark - 库存
-(void)kucun{
     StockVC *applyvc = [[StockVC alloc]init];
    applyvc.modalPresentationStyle = UIModalPresentationFullScreen;
    applyvc.fromto =  fromTypeothercon;
    [self presentViewController:applyvc animated:YES completion:nil];
}
#pragma 商城
-(void)shangcheng{
    ShoppingMainVC *shoppingMainVC = [[ShoppingMainVC alloc]init];
    shoppingMainVC.modalPresentationStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:shoppingMainVC animated:YES completion:nil];
}
#pragma 订单
-(void)dingdan{
   OrderMainVC *applyvc = [[OrderMainVC alloc]init];
    applyvc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:applyvc animated:NO completion:nil];
}
#pragma mark - 代理商
-(void)signalTapAction{
//    [self dismissViewControllerAnimated:NO completion:nil];
    AgentVC *agentvc = [[AgentVC alloc]init];
    agentvc.modalTransitionStyle =     UIModalTransitionStyleCoverVertical;
    [self presentViewController:agentvc animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
